<!DOCTYPE html>

<head>
    <title></title>
    <meta charset="UTF-8">
    <script src="node_modules/jquery/dist/jquery.js"></script>
</head>

<body>
    <script type="text/javascript">
        (function() {
            // 关闭窗口时弹出确认提示
            $(window).bind('beforeunload', function() {
                    // 只有在标识变量is_confirm不为false时，才弹出确认提示
                    if (window.is_confirm !== false)
                        return '您可能有数据没有保存';
                })
                // mouseleavey移入  mouseover移出事件也可以注册在body、外层容器等元素上
                .bind('mouseover mouseleave', function(event) {
                    is_confirm = event.type == 'mouseleave';
                });
        })();
    </script>
</body>

</html>